home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 026-050 / 049 / cycloids / newradii.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  4KB  |  159 lines

  1. /* newradii.c -- open a window to get new radii,
  2. close it, and proceed.... */
  3.  
  4. /************************ Gadget Defines ***********************************/
  5.  
  6. struct IntuiText ntext = {2,2,JAM1, 0, -11, NL,
  7.    (UBYTE *) "Large radius", NL};
  8.  
  9. struct IntuiText ntext2 = {2,2,JAM1, 0, -11, NL,
  10.    (UBYTE *) "Small radius", NL};
  11.  
  12. #define STRINGSIZE 5
  13. UBYTE DefString[STRINGSIZE] = "5";
  14. UBYTE DefString2[STRINGSIZE] = "2";
  15. UBYTE Undo [STRINGSIZE];
  16. UBYTE Undo2 [STRINGSIZE];
  17.  
  18. struct StringInfo TexString = {
  19.    DefString,
  20.    Undo,
  21.    0,
  22.    STRINGSIZE,
  23.    0, 0,
  24.    2,
  25.    0, 0, 0,
  26.    NULL,
  27.    0,
  28.    NULL
  29. };
  30.  
  31. struct StringInfo TexString2 = {
  32.    DefString2,
  33.    Undo2,
  34.    0,
  35.    STRINGSIZE,
  36.    0, 0,
  37.    2,
  38.    0, 0, 0,
  39.    NULL,
  40.    0,
  41.    NULL
  42. };
  43.  
  44. USHORT Pairs[] = {
  45. -1, -1,
  46. 55, -1,
  47. 55, 12,
  48. -1, 12,
  49. -1, -1,
  50. };
  51.  
  52. USHORT Pairs2[] = {
  53. -1, -1,
  54. 55, -1,
  55. 55, 12,
  56. -1, 12,
  57. -1, -1,
  58. };
  59.  
  60. #define NUM_PAIRS 5
  61.  
  62. struct Border StrBorder = {
  63. -1, -1,
  64. 1, 0, JAM1,
  65. NUM_PAIRS,
  66. (APTR)&Pairs,
  67. NULL
  68. };
  69.  
  70. struct Border StrBorder2 = {
  71. -1, -1,
  72. 1, 0, JAM1,
  73. NUM_PAIRS,
  74. (APTR)&Pairs2,
  75. NULL
  76. };
  77.  
  78. #define TEX_GAD 0
  79. #define TEX_GAD2 1
  80.  
  81. struct Gadget tex_gad = {
  82.    &ok_gad2, 10, 25, 50, 11, GADGHCOMP, RELVERIFY,
  83.    STRGADGET, (APTR)&StrBorder, NL,
  84.    &ntext, NL, (APTR)&TexString, TEX_GAD, NL
  85. };
  86.  
  87. struct Gadget tex_gad2 = {
  88.    &tex_gad, 10, 50, 50, 11, GADGHCOMP, RELVERIFY,
  89.    STRGADGET, (APTR)&StrBorder2, NL,
  90.    &ntext2, NL, (APTR)&TexString2, TEX_GAD2, NL
  91. };
  92.  
  93. /* Used to open a Window   */
  94. struct NewWindow NewRwin = {
  95.    10,10, PLX2,PLY2, 2,BCOL, NL,    /* IDCMP set up AFTER CALL */
  96.    ACTIVATE | SMART_REFRESH,
  97.    &tex_gad2,NL, NL,    /* FirstGadget, CheckMark, Title  */
  98.    NL,NL,              /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  99.    PLX2,PLY2,PLX2,PLY2, CUSTOMSCREEN }; /* MinW, MinH, MaxW, MaxH */
  100.  
  101.  
  102. /********************************************************************
  103. * newradii(window)
  104. *    This is the meat. This routine opens the save window and
  105. * retains control until the user selects the OK or CANCEL gadget.
  106. *     The calling arguement is a window pointer.  That window
  107. * is expected to have opened an IDCMP port, which save uses.
  108. ********************************************************************/
  109. int newradii(calling_window)
  110. struct Window *calling_window;
  111. {
  112. struct Window *cW;      /* save window handle   */
  113.  
  114. FAST struct IntuiMessage *imsg;
  115. FAST struct Gadget *igad;
  116.  
  117. FAST int class;
  118. BOOL keepon;
  119. UBYTE temp[5],temp2[5];
  120.  
  121.    /* Get screen from calling window   */
  122.    NewRwin.Screen = calling_window->WScreen;  /* NEED TO SET SCREEN!!! */
  123.    if ( ! (cW = (struct Window *)OpenWindow(&NewRwin)) ) {
  124.       return(FALSE); /* Oops...  */
  125.       }
  126.  
  127.    cW->UserPort = calling_window->UserPort;
  128.    ModifyIDCMP(cW, GADGETUP | GADGETDOWN);
  129.    keepon=TRUE;
  130.    strcpy(temp,DefString);
  131.    strcpy(temp2,DefString2);
  132.    while (keepon == TRUE) {
  133.       while (imsg=(struct IntuiMessage *)GetMsg(cW->UserPort)) {
  134.          class = imsg->Class;
  135.          ReplyMsg(imsg);
  136.          switch ( class ) {
  137.             case GADGETUP:
  138.             case GADGETDOWN:
  139.                igad =(struct Gadget *) imsg->IAddress;
  140.                switch ( igad->GadgetID ) {
  141.                   case CN_GAD2:
  142.                      strcpy(DefString,temp);
  143.                      strcpy(DefString2,temp2);
  144.                      keepon=FALSE;
  145.                      break;
  146.                   case OK_GAD2:
  147.                      aa=atoi(DefString);
  148.                      bb=atoi(DefString2);
  149.                      precalculate();
  150.                      keepon=FALSE;
  151.                      break;
  152.                }
  153.          }
  154.       }
  155.    }
  156.    cW->UserPort = NL;
  157.    CloseWindow(cW);
  158. }
  159.